import cv2
from tkinter import filedialog
import imutils

 
# 读取图像
file_path = filedialog.askopenfilename()
image = cv2.imread(file_path)


 
def crop_ticket(image_path, top, right, bottom, left, output_path):
    # 读取图片
    image = cv2.imread(image_path)
    # 裁剪图片
    cropped = image[top:bottom, left:right]
    # 保存裁剪后的图片
    cv2.imwrite(output_path, cropped)
 
# 假设票据在图片中的坐标如下
top, right, bottom, left = 100, 500, 200, 100
 
# 原始图片路径和输出路径
input_path = 'path_to_your_image.jpg'
output_path = 'path_to_save_cropped_image.jpg'
 
# 裁剪票据
crop_ticket(input_path, top, right, bottom, left, output_path)